package com.sunnada.edu.business.setProcess.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sunnada.edu.system.pub.common.AppContext;
import com.sunnada.edu.system.pub.dao.PubDao;

public class ProcessMethods {

	public static HashMap<String, String> getStatistics(){	
		PubDao dao = AppContext.getInstance().getPubDao();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
		String today = df.format(new Date());
		String sql=" SELECT * FROM(";
		sql+=" (SELECT COUNT(*) total_worker FROM t_worker WHERE REC_STATUS!='2') total_worker,";
		sql+=" (SELECT COUNT(DISTINCT JOBNO) on_duty_worker FROM t_attendance_app WHERE SIGN_TIME LIKE '"+today+"%') on_duty_worker,";
		sql+=" (SELECT COUNT(*) total_project FROM t_project WHERE REC_STATUS!='2') total_project,";
		sql+=" (SELECT COUNT(*) on_work_project FROM t_project WHERE REC_STATUS!='2' AND EDTIME>=NOW()) on_work_project";
		sql+=" ) ";
		List list =dao.selectList(sql);
		HashMap<String, String> map = new HashMap<String, String>();
		if(list!=null&&list.size()>0){
			 map = ((HashMap<String, String>)list.get(0));
		}
		return map;	
	}
	
	
	public static List getProjectStatistics(HashMap<String, String> params){	
		PubDao dao = AppContext.getInstance().getPubDao();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
		String today = df.format(new Date());
		String sr = params.get("sr");
		String cr = params.get("cr");
		String sql=" SELECT * FROM (SELECT  t.name,";
		sql+=" CONCAT(IF(t.BGTIME>NOW(),0,IF(t.EDTIME>NOW(),(ROUND((DATEDIFF(NOW(),t.BGTIME)+1)/(DATEDIFF(t.EDTIME,t.BGTIME)+1),2)*100),100)),'%') process, ";
		sql+=" (SELECT COUNT(*) FROM t_worker w WHERE w.REC_STATUS!='2' and w.GROUPID in(select GROUPID from t_worker_group_project g where g.PROJECTID=t.rec_id ) ) total_worker,";
		sql+=" (SELECT COUNT(DISTINCT a.JOBNO) FROM t_attendance_app a WHERE a.SIGN_TIME LIKE '"+today+"%' AND a.JOBNO IN (SELECT JOBNO FROM t_worker w WHERE w.REC_STATUS!='2' AND w.GROUPID IN(SELECT GROUPID FROM t_worker_group_project g WHERE g.PROJECTID=t.rec_id ) )) in_work_worker ";
		sql+=" FROM t_project t WHERE t.REC_STATUS!='2' order by t.BGTIME desc) t limit "+sr+","+cr+"";
		return dao.selectList(sql);	
	}
	
	
	public static int getProjectStatisticsCount(){	
		PubDao dao = AppContext.getInstance().getPubDao();
		String sql=" SELECT count(*) COT FROM t_project t WHERE t.REC_STATUS!='2' ";
		List list=dao.selectList(sql);
		if(list!=null&&list.size()>0){
			String cot = ((Map)list.get(0)).get("COT")+"";
			return Integer.valueOf(cot);
		}
		return 0;
	}
	

}
